package com.ebt.m.proposal_v2.widget.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.proposal_v2.helper.ThemeHelper;
import com.ebt.m.proposal_v2.utils.ViewUtils;
import com.ebt.m.proposal_v2.widget.base.RadioView;

import butterknife.BindView;

/**
 * 自定义的RadioButton - 性别选择
 *
 * @author archer.qi
 *         Created on 2017/5/5.
 */
public class RadioCell extends RadioView {

    @BindView(R.id.radioText)
    TextView radioText;
    @BindView(R.id.radioCell)
    RelativeLayout radio;
    @BindView(R.id.radioSub)
    ImageView radioSub;

    public RadioCell(Context context) {
        super(context);
    }

    public RadioCell(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray t = context.obtainStyledAttributes(attrs, R.styleable.RadioCell);
        String description = t.getString(R.styleable.RadioCell_text);
        radioText.setText(description);
        boolean isChecking = t.getBoolean(R.styleable.RadioCell_checked, false);
        setCheck(isChecking);
    }


    @Override
    protected int setContentView() {
        return R.layout.radio_cell;
    }

    @Override
    protected void onBindView() {

    }

    @Override
    public void updateCheck(boolean check) {
        ViewUtils.setBackgroundDrawable(radio, check ?
                ThemeHelper.getDrawable(getViewContext(), R.drawable.bg_radio_check) :
                ThemeHelper.getDrawable(getViewContext(), R.drawable.bg_radio_normal));
        radioSub.setVisibility(check ? VISIBLE : GONE);

        int colorCheck = ThemeHelper.getColor(getContext(), R.color.PrimaryThemeColor);
        int colorNormal = ThemeHelper.getColor(getContext(), R.color.PrimaryContentColor);
        radioText.setTextColor(check ? colorCheck : colorNormal);
    }

    public void setText(String text) {
        if (text != null) {
            radioText.setText(text);
        }
    }

    @Override
    public Object getTag() {
        return radioText.getText().toString().trim();
    }
}
